<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的课程 - 学生管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 12px 20px;
            border-radius: 8px;
            margin: 5px 10px;
            transition: all 0.3s;
        }
        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            color: white;
            background: rgba(255, 255, 255, 0.2);
            transform: translateX(5px);
        }
        .main-content {
            background: #f8f9fa;
            min-height: 100vh;
        }
        .course-card {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            transition: transform 0.3s;
            height: 100%;
        }
        .course-card:hover {
            transform: translateY(-5px);
        }
        .course-header {
            border-bottom: 1px solid #eee;
            padding-bottom: 1rem;
            margin-bottom: 1rem;
        }
        .course-title {
            color: #333;
            font-weight: 600;
            margin-bottom: 0.5rem;
        }
        .course-code {
            color: #666;
            font-size: 0.9rem;
        }
        .course-info {
            margin-bottom: 1rem;
        }
        .info-item {
            display: flex;
            align-items: center;
            margin-bottom: 0.5rem;
            color: #666;
            font-size: 0.9rem;
        }
        .info-item i {
            margin-right: 0.5rem;
            width: 16px;
        }
        .btn-drop {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border: none;
            color: white;
            padding: 8px 20px;
            border-radius: 20px;
            font-weight: 500;
            transition: all 0.3s;
        }
        .btn-drop:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(240, 147, 251, 0.4);
            color: white;
        }
        .enrollment-date {
            color: #28a745;
            font-size: 0.8rem;
            font-weight: 500;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3 col-lg-2 px-0">
                <div class="sidebar">
                    <div class="p-3">
                        <h4 class="text-white mb-4">
                            <i class="bi bi-person-circle me-2"></i>学生中心
                        </h4>
                        <nav class="nav flex-column">
                            <a class="nav-link" href="/student/dashboard">
                                <i class="bi bi-house-door me-2"></i>首页
                            </a>
                            <a class="nav-link" href="/student/courses">
                                <i class="bi bi-book me-2"></i>可选课程
                            </a>
                            <a class="nav-link active" href="/student/my-courses">
                                <i class="bi bi-journal-bookmark me-2"></i>我的课程
                            </a>
                            <a class="nav-link" href="/student/schedule">
                                <i class="bi bi-calendar3 me-2"></i>我的课表
                            </a>
                            <a class="nav-link" href="/student/profile">
                                <i class="bi bi-person me-2"></i>个人信息
                            </a>
                            <hr class="text-white-50">
                            <a class="nav-link" href="/logout">
                                <i class="bi bi-box-arrow-right me-2"></i>退出登录
                            </a>
                        </nav>
                    </div>
                </div>
            </div>
            
            <!-- 主内容区 -->
            <div class="col-md-9 col-lg-10">
                <div class="main-content">
                    <div class="p-4">
                        <div class="d-flex justify-content-between align-items-center mb-4">
                            <h2 class="mb-0">我的课程</h2>
                            <div class="d-flex gap-2">
                                <a href="/student/courses" class="btn btn-primary">
                                    <i class="bi bi-plus-circle me-1"></i>浏览更多课程
                                </a>
                            </div>
                        </div>
                        
                        <!-- 成功/错误消息 -->
                        <div th:if="${param.success}" class="alert alert-success alert-dismissible fade show" role="alert">
                            <i class="bi bi-check-circle me-2"></i>
                            <span th:if="${param.success == 'enrolled'}">选课成功！</span>
                            <span th:if="${param.success == 'dropped'}">退课成功！</span>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                        
                        <div th:if="${param.error}" class="alert alert-danger alert-dismissible fade show" role="alert">
                            <i class="bi bi-exclamation-triangle me-2"></i>
                            <span th:text="${param.error}">操作失败</span>
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                        
                        <!-- 课程列表 -->
                        <div class="row g-4">
                            <div class="col-lg-6" th:each="enrollment : ${enrollments}">
                                <div class="course-card">
                                    <div class="course-header">
                                        <h5 class="course-title" th:text="${enrollment.course?.name}">Java程序设计</h5>
                                        <span class="course-code" th:text="${enrollment.course?.courseCode}">CS101</span>
                                    </div>
                                    
                                    <div class="course-info">
                                        <div class="info-item">
                                            <i class="bi bi-person-badge"></i>
                                            <span>教师：<span th:text="${enrollment.course?.teacher?.name}">王教授</span></span>
                                        </div>
                                        <div class="info-item">
                                            <i class="bi bi-award"></i>
                                            <span>学分：<span th:text="${enrollment.course?.credits}">3</span></span>
                                        </div>
                                        <div class="info-item">
                                            <i class="bi bi-info-circle"></i>
                                            <span th:text="${enrollment.course?.description}">Java编程基础课程</span>
                                        </div>
                                        <div class="info-item">
                                            <i class="bi bi-calendar-check"></i>
                                            <span>选课时间：<span th:text="${#temporals.format(enrollment.enrollmentDate, 'yyyy-MM-dd HH:mm')}">2024-01-01 10:00</span></span>
                                        </div>
                                        
                                        <!-- 课程状态 -->
                                        <div class="mt-3">
                                            <span th:if="${enrollment.status == 'ENROLLED'}" 
                                                  class="badge bg-success">已选课</span>
                                            <span th:if="${enrollment.status == 'DROPPED'}" 
                                                  class="badge bg-secondary">已退课</span>
                                        </div>
                                    </div>
                                    
                                    <div class="d-flex justify-content-between align-items-center">
                                        <div class="enrollment-date">
                                            <i class="bi bi-clock me-1"></i>
                                            选课于 <span th:text="${#temporals.format(enrollment.enrollmentDate, 'MM-dd HH:mm')}">01-01 10:00</span>
                                        </div>
                                        <form th:if="${enrollment.status == 'ENROLLED'}" 
                                              th:action="@{/student/drop/{id}(id=${enrollment.course?.id})}" 
                                              method="post" style="display: inline;">
                                            <button type="submit" class="btn btn-drop" 
                                                    onclick="return confirm('确定要退选这门课程吗？')">
                                                <i class="bi bi-dash-circle me-1"></i>退课
                                            </button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 空状态 -->
                        <div th:if="${#lists.isEmpty(enrollments)}" class="text-center py-5">
                            <i class="bi bi-journal-bookmark" style="font-size: 4rem; color: #ccc;"></i>
                            <h4 class="text-muted mt-3">还没有选课</h4>
                            <p class="text-muted">您还没有选择任何课程，快去浏览课程吧！</p>
                            <a href="/student/courses" class="btn btn-primary">
                                <i class="bi bi-search me-1"></i>浏览课程
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
